﻿using UnityEngine;
using System.Collections;

public class Instantiator : MonoBehaviour {

	// Variables
	public GameObject instance;
	private float totalWalkDistance;
	private float position;
	public Transform enemyGuide;

	// Use this for initialization
	void Start () {
		findPosition ();
	}

	private void findPosition(){
		position = enemyGuide.position.y;

		MakeObjectWalk ();
	}

	private void MakeNewObject(){
		GameObject MyNewInstance = (GameObject) Instantiate (instance, transform.position, transform.rotation);
		MyNewInstance.transform.position = new Vector3 (0f, totalWalkDistance, 0f);
	}

	private void MakeObjectWalk(){
		// Distance Generator
		float walkDistance = Random.Range (5f, 10f);
		totalWalkDistance = walkDistance + position;
		Debug.Log ("Distance generated up: " + totalWalkDistance + ".");

		MakeNewObject ();
	}

}
